package no.ntnu.fp.mmi;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import no.ntnu.fp.su.Main;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class MainWindowPanel extends javax.swing.JFrame {
	private JButton goToMaster;
	private JButton goToPlatform;
	private JLabel selectPlatformText;
	private JList platformList;

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/**
	* Constructs a mainwindowpanel, where you decide whether to go to platform or master.
	* Also draws this panel
	*/
	
	public MainWindowPanel(final ArrayList<Integer> platID, ArrayList<String> platName) {
		super();
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			setSize(500, 400);
			{
				goToMaster = new JButton();
				getContentPane().add(goToMaster);
				goToMaster.setText("Go To Master");
				goToMaster.setBounds(156, 27, 219, 28);
				goToMaster.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						Main.startMaster();
						dispose();
						
					}
				});
			}
			{
					
				}
				
				DefaultListModel platformListModel = new DefaultListModel();
				platformList = new JList(platformListModel);
				getContentPane().add(platformList);
				platformList.setModel(platformListModel);
				for (int i = 0; i < platName.size(); i++) {
					platformListModel.add(i,platName.get(i));
				}
				platformList.setBounds(156, 127, 214, 171);
				platformList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
				platformList.addListSelectionListener(new ListSelectionListener() {
					public void valueChanged(ListSelectionEvent e) {
					goToPlatform.setEnabled(true);
					}
				});
			
			{
				selectPlatformText = new JLabel();
				getContentPane().add(selectPlatformText);
				selectPlatformText.setText("Select Platform");
				selectPlatformText.setBounds(156, 105, 214, 16);
				Font font = new Font("Candera", Font.BOLD, 16);
				selectPlatformText.setFont(font);
			}
			{
				goToPlatform = new JButton();
				getContentPane().add(goToPlatform);
				goToPlatform.setText("Go To Platform");
				goToPlatform.setBounds(156, 304, 214, 28);
				goToPlatform.setEnabled(false);
				goToPlatform.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						Main.startWatch(platID.get(platformList.getSelectedIndex()));
						dispose();
						
					}
				});
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
